/* Copyright (c) 2007  Peter Palotas
 *  
 *  This software is provided 'as-is', without any express or implied
 *  warranty. In no event will the authors be held liable for any damages
 *  arising from the use of this software.
 *  
 *  Permission is granted to anyone to use this software for any purpose,
 *  including commercial applications, and to alter it and redistribute it
 *  freely, subject to the following restrictions:
 *  
 *      1. The origin of this software must not be misrepresented; you must not
 *      claim that you wrote the original software. If you use this software
 *      in a product, an acknowledgment in the product documentation would be
 *      appreciated but is not required.
 *  
 *      2. Altered source versions must be plainly marked as such, and must not be
 *      misrepresented as being the original software.
 *  
 *      3. This notice may not be removed or altered from any source
 *      distribution.
 *  
 *  
 *  $Id$
 */

using System;

namespace Plossum.Win32.SystemServices
{
    /// <summary>
    /// Static class providing methods for manipulating string representations of paths.
    /// </summary>
    public static class PathUtils
    {
        /// <summary>
        /// Appends a trailing backslash to the specified path if one does not already exist.
        /// </summary>
        /// <param name="path">The path to which to append the backslash.</param>
        /// <returns>The path specified with a trailing backslash</returns>
        public static string AppendBackslash(string path)
        {
            if (path == null)
                throw new ArgumentNullException("path");

            if (!path.EndsWith("\\"))
                return path + "\\";
            else
                return path;
        }

        /// <summary>
        /// Removes the trailing backslash from the specified <paramref name="path"/> if one exists. Returns the
        /// string untouched otherwise.
        /// </summary>
        /// <param name="path">The path from which to remove an optional trailing backslash</param>
        /// <returns>The <paramref name="path"/> without a trailing backslash</returns>
        public static string RemoveTrailingBackslash(string path)
        {
            if (path == null)
                throw new ArgumentNullException("path");

            if (path.EndsWith("\\"))
                return path.Substring(0, path.Length - 1);

            return path;
        }
    }
}
